<template>
  <div>
    <div :class="className"
      :id="id"
      :style="{height:height,width:width}"></div>
  </div>
</template>
<script>
import echarts from 'echarts'
export default {
  name: 'china-map',
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    id: {
      type: String,
      default: 'chinamap'
    },
    width: {
      type: String,
      default: '1300px'
    },
    height: {
      type: String,
      default: '400px'
    },
    houses: Array
  },
  data() {
    return {
      chart: null
    }
  },
  commputed: {
    dataArr() {
      return this.houses
    }
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById(this.id))
      this.chart.setOption(
        {
          tooltip: {
            trigger: 'item'
          },
          geo: {
            map: 'china',
            label: {
              // emphasis: {
              //   show: false
              // }
              show: true,
              color: '#2a333d'
            },
            // itemStyle: {
            //   areaColor: '#B03A5B',
            //   borderColor: '#B03A5B',
            //   normal: {
            //     areaColor: '#323c48',
            //     borderColor: '#111'
            //   }
            // },
            emphasis: {
              itemStyle: {
                areaColor: '#2a333d'
              }
            }
          },
          roam: true,
          series: [
            {
              name: '房产所在地',
              type: 'scatter',
              coordinateSystem: 'geo',
              data: this.houses, //刚开始为空数组
              symbolSize: 12
            }
          ]
        },
        true
      )
    }
  },
  mounted() {
    this.initChart()
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  }
}
</script>
<style lang="scss">
</style>
